#include <QtGui/QPainter>
#include <QtGui/QColorDialog>
#include <QtCore/QEvent>
#include "colourpicker.hxx"

Ogre::ColourValue ColourPickerWidget::getColour()
{
	return Ogre::ColourValue(mColour.redF(), mColour.greenF(), mColour.blueF());
}

void ColourPickerWidget::paintEvent(QPaintEvent* evt)
{
	QPainter painter(this);
	painter.setClipRect(2, 2, width() - 2, height() - 2);
	painter.setBrush(QBrush(mColour));
	painter.setPen(QColor(0, 0, 0));
	painter.fillRect(QRectF(0, 0, width(), height()), mColour);
	painter.drawRect(2, 2, width() - 3, height() - 3);
}

void ColourPickerWidget::mouseDoubleClickEvent(QMouseEvent* evt)
{
	mColour = QColorDialog::getColor(mColour, this);
	update();
	Ogre::ColourValue value = Ogre::ColourValue(mColour.redF(), mColour.greenF(), mColour.blueF());
	emit colourChanged(value);
}
